<%@page import="java.awt.Window"%>
<%@page import="java.sql.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.util.*,com.sp.model.*"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
<script src="js/pintuer.js"></script>
<%!int curPage=1;
%>
<%if(request.getParameter("curPage")!=null){
	curPage=Integer.valueOf(request.getParameter("curPage"));
} %>
</head>
<body>
<form method="post" action="" id="listform">
  <div class="panel admin-panel">
    <div class="panel-head"><strong class="icon-reorder"> 内容列表</strong> <a href="" style="float:right; display:none;">添加字段</a></div>
    <div class="padding border-bottom">
      <ul class="search" style="padding-left:10px;">
        <li> <a class="button border-main icon-plus-square-o" href="addnews.jsp"> 添加内容</a> </li>
        <li>搜索：</li>
        <li>首页
          <select name="s_ishome" id="s_ishome" class="input"  style="width:60px; line-height:17px; display:inline-block">
            <option value="2">选择</option>
            <option value="1">是</option>
            <option value="0">否</option>
          </select>
          &nbsp;&nbsp;
          推荐
          <select name="s_isvouch" id="s_isvouch" class="input"   style="width:60px; line-height:17px;display:inline-block">
            <option value="2">选择</option>
            <option value="1">是</option>
            <option value="0">否</option>
          </select>
          &nbsp;&nbsp;
          置顶
          <select name="s_istop" id="s_istop" class="input"   style="width:60px; line-height:17px;display:inline-block">
            <option value="2">选择</option>
            <option value="1">是</option>
            <option value="0">否</option>
          </select>
        </li>
        <if condition="$iscid eq 1">
          <li>
            <select name="cid" class="input" style="width:200px; line-height:17px;" id="newsType" >
              <option value="" >请选择类别</option>
               <%
     NTypeOper ntop=new NTypeOper();
     ArrayList<NTypeBean> al=ntop.GetTypeList();
     NTypeBean nt;
     int i;
        for(i=0;i<al.size();i++)  
                {  
                    nt=(NTypeBean)al.get(i);  
   %> 
           
                <option value=<%=nt.getTid()%> ><%=nt.getTname() %></option>
              <%} %>
       
            </select>
            
     
          </li>
        </if>
        <li>
          <input type="text" placeholder="请输入搜索关键字" id="keywords" name="keywords" class="input" style="width:250px; line-height:17px;display:inline-block" />
          <a href="javascript:void(0)" class="button border-main icon-search" id="searchSelective"  > 搜索</a></li>
      </ul>
    </div>
    <table class="table table-hover text-center" id="newsTable">
      <tr>
        <th width="100" style="text-align:left; padding-left:20px;">ID</th>
    
        <th>标题</th>
        <th>类别名称</th>
        <th>发布者</th>
        <th>属性</th>
        <th width="10%">添加时间</th>
        <th width="10%">更新时间</th>
        <th width="310">操作</th>
      </tr>
      <!-- <volist name="list" id="vo"> -->
      <%!public String getAttribute(NewsBean news){
      StringBuffer sb = new StringBuffer();
      if(news.getInhome()==1)
      	sb.append("首页");
      if(news.getIsvouch()==1){
      if(sb.length()==0){
      sb.append("推荐");
      }else{sb.append(",推荐");}
      }
      if(news.getIstop()==1){
      if(sb.length()==0){
      sb.append("置顶");
      }
      else{sb.append(",置顶");}
      }
      return sb.toString();
      } %>
      <%if(session.getAttribute("newsList")!=null){
      	List<NewsBean> newsList = (List<NewsBean>)session.getAttribute("newsList");
		session.setAttribute("newsList", newsList);
		session.setAttribute("pageCount", newsList.size());
      	NewsBean news;
      	String result=null;
      	int temp=0;
      	//设定一页6张
      	if(newsList.size()>0){
      	while(temp<6&&((curPage-1)*6+temp)<newsList.size()){
      	news = newsList.get((curPage-1)*6+temp);
      	result="<tr><td style='text-align:left; padding-left:20px;'><input type='checkbox' name='id[]' value='"+news.getId()+
      		"'/>"+news.getId()+"</td><td>"+news.getTitle()+"</td><td>"+new NTypeOper().GetTypeById(news.getTid()).getTname()+
      		"</td><td>"+news.getUname()+"</td><td><font color='#00CC99'>"+getAttribute(news)+"</font></td><td>"+news.getAddTime()+"</td><td>"+news.getUpdateTime()+
      		"</td><td><div class='button-group'> <a class='button border-main' href='newsedit.jsp?id="+news.getId()+"'><span class='icon-edit'>"+
      		"</span> 修改</a> <a class='button border-red' href='javascript:void(0)' onclick='del("+news.getId()+")'><span class='icon-trash-o'></span> 删除</a> </div></td></tr>";
      		
      		/* "&title="+news.getTitle()+"&picture="+news.getPicture()+"&tid="+news.getTid()+"&inhome="+news.getInhome()+
      		"&isvouch="+news.getIsvouch()+"&istop"+news.getIstop()+"&content="+news.getContent()+"&uname="+news.getUname()+ */
      	out.print(result);
      	temp++;
      	}
      	}
      	}
      	else{
      	%>
      	<script>
      	window.location.href="SelectNewsSelectiveServlet";
      	</script>
      	<%
      	
      	}
      	
      	
      %>
        <!-- <tr>
          <td style="text-align:left; padding-left:20px;"><input type="checkbox" name="id[]" value="" />
           1</td>
            <td>这是一套MUI后台精美管理系统，感谢您的支持</td>
             <td>产品分类</td>
              <td>管理员</td>
             <td><font color="#00CC99">首页</font></td>
                <td>2016-07-01</td>
                   <td>2016-07-01</td>
              
          <td><div class="button-group"> <a class="button border-main" href="add.html"><span class="icon-edit"></span> 修改</a> <a class="button border-red" href="javascript:void(0)" onclick="return del(1,1,1)"><span class="icon-trash-o"></span> 删除</a> </div></td>
        </tr>
        
              <tr>
          <td style="text-align:left; padding-left:20px;"><input type="checkbox" name="id[]" value="" />
           1</td>
            <td>这是一套MUI后台精美管理系统，感谢您的支持</td>
             <td>产品分类</td>
              <td>管理员</td>
             <td><font color="#00CC99">首页</font></td>
                <td>2016-07-01</td>
                   <td>2016-07-01</td>
              
          <td><div class="button-group"> <a class="button border-main" href="add.html"><span class="icon-edit"></span> 修改</a> <a class="button border-red" href="javascript:void(0)" onclick="return del(1,1,1)"><span class="icon-trash-o"></span> 删除</a> </div></td>
        </tr> -->
        
   		
        <td style="text-align:left; padding:19px 0;padding-left:20px;"><input type="checkbox" id="checkall"/>
          全选 </td>
        <td colspan="7" style="text-align:left;padding-left:20px;"><a href="javascript:void(0)" class="button border-red icon-trash-o" style="padding:5px 15px;" onclick="DelSelect()"> 删除</a> 
          
       
      </tr>
      <tr>
        <td colspan="8"><div class="pagelist"> 
        <%
        int pageTemp=1;
        int totalCount = Integer.valueOf((session.getAttribute("pageCount")!=null?session.getAttribute("pageCount"):6).toString());
        int totalPage =(totalCount%6==0)?totalCount/6:(totalCount/6+1);
        		
        if(curPage==1){
        out.print("<a>上一页</a>");}
        else{
        out.print("<a href='newslist.jsp?curPage="+(curPage-1)+"'>上一页</a>");}
        
        
        for(pageTemp=1;pageTemp<=totalPage;pageTemp++){
        if(pageTemp==curPage){
        out.print("<span class='current'>"+pageTemp+"</span>");
        }
        else{
        out.print("<a href='newslist.jsp?curPage="+pageTemp+"'>"+pageTemp+"</a>");}
        }
        
        if(curPage==totalPage){
        out.print("<a>下一页</a>");
        out.print("<a>尾页</a>");}
        else{
        out.print("<a href='newslist.jsp?curPage="+(curPage+1)+"'>下一页</a>");
        out.print("<a href='newslist.jsp?curPage="+totalPage+"'>尾页</a>"); }       
        %>
		</div>
		</td>
      </tr>
    </table>
  </div>
</form>
<script type="text/javascript">
$(document).ready(function(){
$("#searchSelective").click(function(){
var ishome = $("#s_ishome").val();
var isvouch = $("#s_isvouch").val();
var istop = $("#s_istop").val();
var newsType = $("#newsType").val();
//alert(newsType);
var keywords = $("#keywords").val();
var url="SelectNewsSelectiveServlet?";
if(ishome!=2)
url = url+"ishome="+ishome+"&";
if(isvouch!=2)
url = url+"isvouch="+isvouch+"&";
if(istop!=2)
url = url+"istop="+istop+"&";
if(newsType!="")
url = url+"newsType="+newsType+"&";
if(keywords!="")
url = url+"keywords="+keywords+"&";
url=url.substring(0, url.length-1);
//alert(url);
window.location.href=url;

});

/* //搜索
function changesearch(){	
		var ishome = document.getElementsByName("s_ishome");
} */



//全选
$("#checkall").click(function(){ 
  $("input[name='id[]']").each(function(){
	  if (this.checked) {
		  this.checked = false;
	  }
	  else {
		  this.checked = true;
	  }
  });
})
}
);

	
	/*  $("input[name='id[]']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){
		var t=confirm("您确认要删除选中的内容吗？");
		if (t==false) return false;		
		$("#listform").submit();		
	}
	else{
		alert("请选择您要删除的内容!");
		return false;
	} */


//批量排序
/* function sorts(){
	var Checkbox=false;
	 $("input[name='id[]']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){	
		
		$("#listform").submit();		
	}
	else{
		alert("请选择要操作的内容!");
		return false;
	}
}*/
 
//单个删除
function del(id){
	if(confirm("您确定要删除吗?")==true){
		window.location.href="DeleteNewsServlet?id="+id+"";
	} 
}

//批量删除
function DelSelect(){
	var Checkbox=false;
	
	var checkboxs = document.getElementsByName("id[]");
	//alert(checkboxs);
	var ids = new Array();
	for(var i=0;i<checkboxs.length;i++){
		if(checkboxs[i].checked==true){
		ids.push(checkboxs[i].value);
		}
	}
	if(ids.length==0){
	alert("请选择需要删除的内容");
	return;}else{
	if(confirm("您确认要删除选中的内容吗？")==true)
	window.location.href="DeleteNewsServlet?ids="+ids+"";}}
//批量首页显示
/* function changeishome(o){
	var Checkbox=false;
	 $("input[name='id[]']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){
		
		$("#listform").submit();	
	}
	else{
		alert("请选择要操作的内容!");		
	
		return false;
	}
} */

//批量推荐
/* function changeisvouch(o){
	var Checkbox=false;
	 $("input[name='id[]']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){
		
		
		$("#listform").submit();	
	}
	else{
		alert("请选择要操作的内容!");	
		
		return false;
	}
} */

//批量置顶
/* function changeistop(o){
	var Checkbox=false;
	 $("input[name='id[]']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){		
		
		$("#listform").submit();	
	}
	else{
		alert("请选择要操作的内容!");		
	
		return false;
	}
} */


//批量移动
/* function changecate(o){
	var Checkbox=false;
	 $("input[name='id[]']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){		
		
		$("#listform").submit();		
	}
	else{
		alert("请选择要操作的内容!");
		
		return false;
	}
} */

//批量复制
/* function changecopy(o){
	var Checkbox=false;
	 $("input[name='id[]']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){	
		var i = 0;
	    $("input[name='id[]']").each(function(){
	  		if (this.checked==true) {
				i++;
			}		
	    });
		if(i>1){ 
	    	alert("只能选择一条信息!");
			$(o).find("option:first").prop("selected","selected");
		}else{
		
			$("#listform").submit();		
		}	
	}
	else{
		alert("请选择要复制的内容!");
		$(o).find("option:first").prop("selected","selected");
		return false;
	}
} */


</script>
</body>

</html>